//
//  EFBMainViewController.m
//  ChartKit
//
//  Created by E.F.B on 15-5-27.
//  Copyright (c) 2015年 LiuYanli. All rights reserved.
//

#import "EFBMainViewController.h"
#import "EFBChartsViewController.h"
#import "TCAirportModel.h"
#import "EFBTopView.h"
@interface EFBMainViewController ()
@property (nonatomic, retain) NSArray *itemsArray;
@property (nonatomic, retain) NSArray *itemsArray1;
@property (nonatomic, retain) UIButton *versionButton;
@property (nonatomic, retain) EFBTopView *topView;
@property (nonatomic, retain) EFBChartsViewController *chartView;
@end


@implementation EFBMainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadName:) name:@"kChartName" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pdfTapped:) name:@"pdfTapped" object:nil];

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:213/255.0 green:216/255.0 blue:223/255.0 alpha:1.0f];
    self.chartView = [[[EFBChartsViewController alloc] init]autorelease];
    self.chartView.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:self.chartView.view];
    
    EFBAccessoryBarItem *item = [[EFBAccessoryBarItem alloc] initWithStyleClass:@"accessory-lock" target:self action:@selector(barButtonItemTapped:)];
    
    EFBAccessoryBarItem *itemMark = [[EFBAccessoryBarItem alloc] initWithStyleClass:@"accessory-Nomark" target:self action:@selector(barButtonItemTapped:)];
    
    EFBAccessoryBarItem *itemRotate = [[EFBAccessoryBarItem alloc] initWithStyleClass:@"accessory-rotate" target:self action:@selector(barButtonItemTapped:)];
    
    self.itemsArray = @[item,itemMark,itemRotate];
    self.itemsArray1 = @[item,itemMark];
    self.accessoryItems = self.itemsArray;
    
    [self didFinishLoadView];

}

- (void) reloadName:(NSNotification *)object
{
    self.topView.titleLabel.text  = object.object;
}

- (void)barButtonItemTapped:(id)sender
{
    EFBAccessoryBarItem *item = (EFBAccessoryBarItem *)sender;
    switch (item.tag)
    {
        case 0:
        {
            [self lockScreen];
        }
            break;
        case 1:
        {
            EFBAccessoryBarItem *bar = [self.accessoryItems objectAtIndex:item.tag];
            bar.selected = !bar.selected;
            
            self.accessoryItems = self.accessoryItems;
            NSNotification* notification1 = [NSNotification notificationWithName:kContextPDFMark object:[NSNumber numberWithBool:bar.selected]];
            [[NSNotificationCenter defaultCenter] postNotification:notification1];
        }
            break;
        case 2:
        {
            NSNotification* notification = [NSNotification notificationWithName:kConextPDFRotation object:nil];
            [[NSNotificationCenter defaultCenter] postNotification:notification];
        }
            break;
        default:
            break;
    }
}

- (void)pdfTapped:(NSNotification*)no
{
    BOOL isHidden = [no.object boolValue];
    self.fullScreenMode = isHidden;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
